import { ElMessage, ElMessageBox } from "element-plus";

type MessageType = "success" | "warning" | "info" | "error";

export function useToastHooks() {
  const toastHook = (
    opt: Object = {},
    message: string,
    type: MessageType,
    duration?: number,
    offset?: number
  ) => {
    return ElMessage({
      ...opt, // 用户自定义配置优先
      message,
      type: type || "info",
      duration: duration || 1000,
      offset: offset || 100,
    });
  };

  // 快捷方法
  const successToast = (message: string) => toastHook(message, "success");
  const warningToast = (message: string) => toastHook(message, "warning");
  const infoToast = (message: string) => toastHook(message, "info");
  const errorToast = (message: string) => toastHook(message, "error");

  return {
    toastHook,
    successToast,
    warningToast,
    infoToast,
    errorToast,
  };
}
